home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-01-10 | 3.5 KB | 139 lines | [TEXT/MPS ] |
- /*
- WindowDef_main.cp
-
- Main function for all WindowDef's.
-
- C++ Implementation by Patrick Beard.
-
- ©1990 by Patrick C. Beard. All rights reserved.
- */
-
- #include <StdDef.h>
- #include <Memory.h>
- #include <Events.h>
-
- #include "VirtualWorld.h"
-
- // The next two lines will change depending on the WDEF being built
-
- #include "IconWDEF.h"
- #define WINDOWCLASS IconWindowDef
-
- // structure to maintain our storage.
-
- struct WindowDefinitionData {
- WStateData states;
- VirtualWorld *world;
- };
-
- typedef WindowDefinitionData *WindowDefinitionDataPtr, **WindowDefinitionDataHandle;
-
- static WindowDefinition* theWindowDef; // global to maintain our window def object.
-
- pascal long main(short varCode, WindowPeek theWindow, short message, long param)
- {
- long result = 0;
-
- // see if the command key is down for debugging purposes.
- KeyMap theKeys;
- GetKeys(theKeys);
- Boolean commandKeyDown = (theKeys[1] & (1L<<15)) != 0;
-
- if(commandKeyDown)
- DebugStr("\pChecking theWorld.");
-
- // retrieve our global context from the window record.
- VirtualWorld* theWorld;
- WindowDefinitionDataHandle theData = (WindowDefinitionDataHandle)theWindow->dataHandle;
- if(theData) {
- theWorld = (**theData).world;
- theWorld->Enter();
- }
-
- switch(message) {
- case wNew:
- // create a world to support virtual functions.
- if(commandKeyDown)
- DebugStr("\pCreating VirtualWorld.");
- theWorld = new VirtualWorld(true); // true means our code resource floats.
- if(!theWorld || theWorld->Result()) {
- delete theWorld;
- break;
- }
- theData = (WindowDefinitionDataHandle)NewHandle(sizeof(WindowDefinitionData));
- theWindow->dataHandle = (Handle)theData;
- (**theData).world = theWorld; // save reference in window record.
- theWorld->Enter(); // go into our Virtual world.
- // now, allocate the Window object.
- theWindowDef = new WINDOWCLASS;
- if(!theWindowDef) {
- delete theWorld; // it didn't work. get outta here.
- theWorld = nil;
- theWindow->dataHandle = nil;
- break;
- }
- if(commandKeyDown)
- DebugStr("\pCalling WindowDefinition::New().");
- // call it's new method.
- theWindowDef->New(theWindow);
- break;
- case wDispose:
- if(!theWorld) break;
- if(commandKeyDown)
- DebugStr("\pCalling WindowDefinition::Dispose().");
- theWindowDef->Dispose(); // kill the window def.
- delete theWindowDef;
- theWindowDef = nil;
- delete theWorld; // remove our Virtual world.
- theWorld = nil;
- DisposHandle(theWindow->dataHandle);
- theWindow->dataHandle = nil;
- break;
- case wCalcRgns:
- if(!theWorld) break;
- if(commandKeyDown)
- DebugStr("\pCalling WindowDefinition::CalcRgns().");
- theWindowDef->CalcRgns();
- break;
- case wDraw:
- if(!theWorld) break;
- switch((short)param) {
- case wNoHit:
- if(commandKeyDown)
- DebugStr("\pCalling WindowDefinition::DrawFrame().");
- theWindowDef->DrawFrame();
- break;
- case wInGoAway:
- if(commandKeyDown)
- DebugStr("\pCalling WindowDefinition::DrawGoAwayBox().");
- theWindowDef->DrawGoAwayBox();
- break;
- }
- break;
- case wDrawGIcon:
- if(!theWorld) break;
- if(commandKeyDown)
- DebugStr("\pCalling WindowDefinition::DrawGIcon().");
- theWindowDef->DrawGIcon();
- break;
- case wGrow:
- if(!theWorld) break;
- if(commandKeyDown)
- DebugStr("\pCalling WindowDefinition::Grow().");
- theWindowDef->DrawGrowImage(*(Rect*)param);
- break;
- case wHit:
- if(!theWorld) break;
- if(commandKeyDown)
- DebugStr("\pCalling WindowDefinition::Hit().");
- result = theWindowDef->Hit(*(Point*)¶m);
- break;
- }
-
- if(theWorld) {
- theWorld->Leave(); // go back to previous world.
- }
-
- return result;
- }
-